var id = T.p("id");
var subjectList = T.getDictDynas("subject");

var vm = new Vue({
    el: '#rrapp',
    data: {
        title: "新增",
        scheduleJob: {
            status: 1
        },
        misfireInformIds: [],
        misfireInformIdList: []
    },
    created: function () {
        if (id != null) {
            this.title = "修改";
            this.getInfo(id)
        }
    },
    mounted: function () {
        $('#cronFrame').load(function () {
            var win = $(this)[0].contentWindow;
            // win.$('#cron').val($('#cronExpression').val());
            win.$('#cron').val(vm.scheduleJob.cronExpression);
            win.$("input[name^='v_'],#cron").change(function () {
                //$('#cronExpression').val(win.$('#cron').val());
                vm.scheduleJob.cronExpression = win.$('#cron').val();
            });
            win.$('#btnFan').click();
        });
        this.misfireInformIdList = T.getDictDynas("misfire_inform");
    },
    methods: {
        getInfo: function (id) {
            $.get("../scheduleJob/info/" + id, function (r) {
                vm.scheduleJob = r.scheduleJob;
                if (r.scheduleJob.misfireInformIds) {
                    vm.misfireInformIds = r.scheduleJob.misfireInformIds.split(",");
                }
            });
        },
        saveOrUpdate: function (event) {
            var url = vm.scheduleJob.id == null ? "../scheduleJob/save" : "../scheduleJob/update";
            vm.scheduleJob.misfireInformIds = vm.misfireInformIds.join(",");
            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(vm.scheduleJob),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.back();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        back: function (event) {
            history.go(-1);
        }
    }
});

